﻿

#region NameSpace
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using UserManage;
using Eb.StockManagement;
#endregion

public partial class BusinessProcessAutomation : System.Web.UI.MasterPage
{
    
    UserManager _userSearch = new UserManager();
    Control _uc;

   
    #region Fields
    #endregion

  

    #region Methods

    /// <summary>
    /// get /set ViewState
    /// </summary>
    private string LastLoadedControl
    {
        get
        {
            return ViewState["LastLoaded"] as string;
        }
        set
        {
            ViewState["LastLoaded"] = value;
        }
    }

    /// <summary>
    /// Load UserControl Dynamically
    /// </summary>
    /// <param name="ss"></param>
    private void LoadUserControl(string ss)
    {
        string controlPath = ss;

        if (!string.IsNullOrEmpty(controlPath))
        {
            PlaceHolder1.Controls.Clear();
            controlPath = ss;
            LastLoadedControl = controlPath;
            UserControl uc = (UserControl)LoadControl(controlPath);
            // PlaceHolder1.EnableViewState=false;
            PlaceHolder1.Controls.Add(uc);
        }
    }
    #endregion

    #region Events

   
    /// <summary>
    /// Page Load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Session["ConnectionString"] = ConfigurationManager.ConnectionStrings["connectUserManager"].ToString();
        if (Session["UserId"] != null)
        {
     

            string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            
            System.IO.FileInfo fileName = new System.IO.FileInfo(sPath);
            string currentPath = fileName.Name;
            
                if (Request.Params["Sel"] != null)
                {
                    char splitter = ';';
                    string path = Request.Params["Sel"].ToString();
                    string[] splitid = path.Split(splitter);
                    Session["Path"] = splitid[0];
                    Session["requestTypeId"] = splitid[1];
                }


                if (Session["FirstName"] != null)
                {
                    lblWelcomeMessage.Text = "Welcome " + Session["FirstName"].ToString();
                }
                else
                {
                    lblWelcomeMessage.Visible = false;
                }

            PlaceHolder1.Controls.Clear();
            if (Request.QueryString["Sel"] != null)
            {
                if (Session["Path"].ToString() == "~/Modules/TaskList.ascx")
                {
                    Session["UserManager_Control"] = "TaskList.ascx";
                    Response.Redirect("~/BusinessProcessAutomation.aspx");
                     //Session["UserManager_Control"] = "TaskList.ascx"; ;
                     //LoadUserControl(Session["Path"].ToString());
                }
                else
                {

                    Session["UserManager_Control"] = null;
                    LoadUserControl(Session["Path"].ToString());
                }
            }
            else
            {
                if (Session["UserManager_Control"] != null)
                {
                    string basePath = "~/Modules/";
                    PlaceHolder1.Controls.Clear();
                    _uc = (UserControl)LoadControl(basePath + Session["UserManager_Control"].ToString());
                    PlaceHolder1.Controls.Add(_uc);
                }
            }
        }
    }



    #endregion
    protected void lbLogOut_Click(object sender, EventArgs e)
    {
        Response.Buffer = true;
        Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
        Response.Expires =-1500;
        Response.CacheControl = "no-cache";
        Session.Clear();
        Session.Abandon();
        if (Session["UserId"] == null)
            {
                FormsAuthentication.RedirectToLoginPage();
	       // Response.Redirect ("Login.aspx");
            }

    }
    protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
    {
        //ScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message + e.Exception.StackTrace;
    }
}
